package org.grow.present.controller.purchase;

import org.grow.present.entity.ExpensesAnalysis;
import org.grow.present.mapper.ExpensesAnalysisMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.List;

/**
 * @Author: xwg
 * @CreateDate: 2024/10/3
 */

@RestController
@RequestMapping("/expensesAnalysis")
public class ExpensesAnalysisController {
    @Autowired
    private ExpensesAnalysisMapper expensesAnalysisMapper;

    @GetMapping("/annualExpenses/{year}")
    public List<ExpensesAnalysis> annualExpenses(@PathVariable("year") Integer year) {
        if (year == 0) {
            year = LocalDate.now().getYear();
        }
        LocalDate min = LocalDate.now().withYear(year).with(TemporalAdjusters.firstDayOfYear());
        ;
        LocalDate max = LocalDate.now().withYear(year).with(TemporalAdjusters.lastDayOfYear());
        System.out.println(max + " -- " + min);
        List<ExpensesAnalysis> s = expensesAnalysisMapper.findByStartEnd(min, max);
        return s;


    }
}
